package cn.sumpu.app.coolsk.dao.impl;

import java.util.List;
import java.util.Map;

import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.slf4j.*;
import cn.sumpu.app.coolsk.dao.*;
import cn.sumpu.app.coolsk.domain.Syslog;
import cn.sumpu.app.coolsk.exception.AppBusinessException;

public class SyslogDaoImpl extends SqlSessionDaoSupport implements SyslogDao {
	
	private final static Logger logger = LoggerFactory
			.getLogger(SyslogDaoImpl.class);

	//添加系统日志
	@Override
	public void addSyslog(Syslog syslog) throws AppBusinessException {
		try {
			getSqlSession().insert("cn.sumpu.app.coolsk.persistence.SyslogMapper.addSyslog", syslog);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("addSyslog resource failure.", e);
			}
			throw new AppBusinessException("addSyslog resource failure.", e);
		}
	}
	//查询系统日志
	@SuppressWarnings("unchecked")
	@Override
	public List<Syslog> getSyslogs(Map<String, Object> map)
			throws AppBusinessException {
		try {
			return getSqlSession().selectList("cn.sumpu.app.coolsk.persistence.SyslogMapper.getSyslogs", map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getSyslogs resource failure.", e);
			}
			throw new AppBusinessException("getSyslogs resource failure.", e);
		}
	}
	//查询系统日志总条数
	@Override
	public Integer getSyslogsCount(Map<String, Object> map)
			throws AppBusinessException {
		try {
			return (Integer) getSqlSession().selectOne("cn.sumpu.app.coolsk.persistence.SyslogMapper.getSyslogsCount", map);
		} catch (Exception e) {
			if (logger.isErrorEnabled()) {
				logger.error("getSyslogsCount resource failure.", e);
			}
			throw new AppBusinessException("getSyslogsCount resource failure.", e);
		}
	}

}
